package ui;

import java.awt.CardLayout;
import java.util.Vector;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

import simulationEngine.SimulationEngine;
import datatypes.DiscoveryMechanismEnum;
import datatypes.ScenarioDescription;

@SuppressWarnings("serial")
public class SimulationExecutionCardContainer extends JPanel {

	private final static String Karte1 = "Statistiken";
	private final static String Karte2 = "Discovery";
	private final static String Karte3 = "Logical_Network";
	private final static String Karte4 = "Physical_Network";
	private final static String Karte5 = "Roster";
	
	private static Vector <String> cardnames = null;
	
	private CardLayout layout = new CardLayout();
	
	private SimulationExecutionStatisticCard card1 = null;
	private SimulationExecutionDiscoveryCard card2 = null;
	private SimulationExecutionLogNetworkCard card3 = null;
	private SimulationExecutionPhysNetworkCard card4 = null;
	private SimulationExecutionRosterCard card5 = null;
	
	private SimulationEngine engine = null;
	
	public DiscoveryMechanismEnum mech = null;
	
	public SimulationExecutionCardContainer (int SimulationIDinDB ,ScenarioDescription scenDesc, DiscoveryMechanismEnum mech){
		super();
		this.mech = mech;
		this.engine = new SimulationEngine(SimulationIDinDB, scenDesc, this);
		this.setLayout(layout);
		this.add(this.getCard5(), Karte5);
		this.add(this.getCard4(), Karte4);
		this.add(this.getCard3(), Karte3);
		this.add(this.getCard2(), Karte2);
		this.add(this.getCard1(), Karte1);
		this.showCard(Karte1);
	}
	
	
	public Vector<String> getCardNames(){
		if (cardnames == null){
			cardnames = new Vector<String>();
			cardnames.add(Karte5);
			cardnames.add(Karte4);
			cardnames.add(Karte3);
			cardnames.add(Karte2);
			cardnames.add(Karte1);
		}
		return cardnames;
	}
	
	
	private JPanel getCard1(){
		if (card1 == null){
			card1 = new SimulationExecutionStatisticCard(this.engine);
		}
		return card1;
	}

	private JScrollPane getCard2(){
		if (card2 == null){
			card2 = new SimulationExecutionDiscoveryCard();
		}
		return card2;
	}

	private JScrollPane getCard3(){
		if (card3 == null){
			card3 = new SimulationExecutionLogNetworkCard();
		}
		return card3;
	}

	private JScrollPane getCard4(){
		if (card4 == null){
			card4 = new SimulationExecutionPhysNetworkCard(this.engine);
		}
		return card4;
	}

	private JScrollPane getCard5(){
		if (card5 == null){
			card5 = new SimulationExecutionRosterCard(this.engine);
		}
		return card5;
	}

	public void showCard (String cardname){
		System.out.println(cardname);
		layout.show(this, cardname);
	}

	//execution Logik
	public void startScenarioSimulation(int numberOfSteps){	
		this.engine.startSimulation(numberOfSteps);
	}
	
	public void stopScenarioSimulation(){
		this.engine.stopSimulation();
	}
	
	public SimulationExecutionStatisticCard getStatisticCard(){
		return (SimulationExecutionStatisticCard)this.getCard1();
	}
}
